package com.wjggy.core.common.util.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

/**
 * 
 *  <p>Description:  常用过滤器</p>
 *  <p>Copyright:Copyright (c) 2012  </p>
 *  <p>Company:wjggy  </p>
 *  @author xiaofan.yu  
 *  @date   2012-1-8 下午10:18:03    
 *  @project  wjggy
 *  @version  1.0.0
 *  @see   
 *  @since 1.6
 */
public class CommsFilter  implements Filter
{
	private static final Logger log = Logger.getLogger(CommsFilter.class);
	public static String charset;
	/**
	 * Attribute name indicating the filter has been applied to a given request.
	 */
	private final static String FILTER_APPLIED = "request";

	/**
	 * 设置字符编码
	 * 
	 * @param request The request
	 * @param response The response
	 * @param chain The processing chain
	 * @throws IOException If an error occurs
	 * @throws ServletException If an error occurs
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
			ServletException
	{		
		request.setAttribute(FILTER_APPLIED, request);
		HttpServletRequest req=(HttpServletRequest)request;
		request.setCharacterEncoding(charset);
		response.setCharacterEncoding(charset);
		chain.doFilter(request, response);
	}

	/**
	 * Initializes this filter.
	 * 
	 * @param filterConfig The filter configuration
	 * @throws ServletException If an error occurs
	 */
	public void init(FilterConfig filterConfig) throws ServletException {}

	/**
	 * Destroys this filter.
	 */
	public void destroy() {}
}
